<?php

namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;

class LoginController extends Controller{
    public function verify(Request $request){
        $data=$request['data'];
        $rules = ['data.code' => 'required|captcha'];
        $validator = validator()->make(request()->all(), $rules);
        if ($validator->fails()) {
            return 0;
        }
        $rows=DB::table('user')
            ->where([
                "username"=>$data['username'],
                "password"=>$data['password']
            ])
            ->limit(1)
            ->first();
        if($rows){
            session(['username'=>$data['username']]);
            return 1;
        }
        return -1;

    }
}